using System;
using System.Collections.Generic;
using System.Text;

namespace SmartMathLibrary.Management
{
    /// <summary>
    /// This class represents a state object, which includes two states. If the first state A is set 
    /// to true, the second state B will be set automatically to false.
    /// </summary>
    [Serializable]
    public class DualState
    {
        /// <summary>
        /// The first state of the object.
        /// </summary>
        private bool a;

        /// <summary>
        /// The second state of the object.
        /// </summary>
        private bool b;

        /// <summary>
        /// Initializes a new instance of the <see cref="DualState"/> class.
        /// </summary>
        public DualState()
        {
            this.a = true;
            this.b = false;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="DualState"/> class.
        /// </summary>
        /// <param name="state">The state of the instance.</param>
        public DualState(bool state)
        {
            this.a = state;
            this.b = !state;
        }

        /// <summary>
        /// Gets or sets the first state of the state object.
        /// </summary>
        /// <value>The first state of the state object.</value>
        public bool A
        {
            get { return a; }
            set
            {
                a = value;
                b = !value;
            }
        }

        /// <summary>
        /// Gets or sets the second state of the state object.
        /// </summary>
        /// <value>The second state of the state object.</value>
        public bool B
        {
            get { return b; }
            set
            {
                a = !value;
                b = value;
            }
        }

        /// <summary>
        /// Switches the state of the instance.
        /// </summary>
        public void SwitchState()
        {
            this.a = !this.a;
            this.b = !this.b;
        }

        /// <summary>
        /// Compares the current instance with another state instance.
        /// </summary>
        /// <param name="compare">The state object to compare.</param>
        /// <returns>True if the specified state instance is even to the current 
        /// instance object.</returns>
        public bool CompareTo(DualState compare)
        {
            return this == compare;
        }

        /// <summary>
        /// Implements the operator ==.
        /// </summary>
        /// <param name="a">The first state object.</param>
        /// <param name="b">The second state object.</param>
        /// <returns>The result of the operator.</returns>
        public static bool operator ==(DualState a, DualState b)
        {
            return ((a.A == b.A) && (a.B == b.B));
        }

        /// <summary>
        /// Implements the operator !=.
        /// </summary>
        /// <param name="a">The first state object.</param>
        /// <param name="b">The second state object.</param>
        /// <returns>The result of the operator.</returns>
        public static bool operator !=(DualState a, DualState b)
        {
            return !(a == b);
        }

        /// <summary>
        /// Determines whether the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>.
        /// </summary>
        /// <param name="obj">The <see cref="T:System.Object"/> to compare with the current <see cref="T:System.Object"/>.</param>
        /// <returns>
        /// true if the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>; otherwise, false.
        /// </returns>
        /// <exception cref="T:System.NullReferenceException">The <paramref name="obj"/> parameter is null.</exception>
        public override bool Equals(object obj)
        {
            return base.Equals(obj);
        }

        /// <summary>
        /// Serves as a hash function for a particular type.
        /// </summary>
        /// <returns>
        /// A hash code for the current <see cref="T:System.Object"/>.
        /// </returns>
        public override int GetHashCode()
        {
            return base.GetHashCode();
        }

        /// <summary>
        /// Returns a <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </summary>
        /// <returns>
        /// A <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </returns>
        public override string ToString()
        {
            return a.ToString() + "; " + b.ToString();
        }
    }
}